{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# lab 3mf output\n",
    "\n",
    "in addition to transforming a fullcontrol ***design*** into a 'gcode' ***result***, it can also be transformed into other types of 'control_code' ***results*** - for example for robots, subtractive technologies, etc.\n",
    "\n",
    "this notebook demonstrates output of a .3mf file for a Bambulab X1 printers, which can be opened by Bambu Studio and sent to the printer via the cloud"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### FullControl lab import"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "if 'google.colab' in str(get_ipython()):\n  !pip install git+https://github.com/FullControlXYZ/fullcontrol --quiet\nimport fullcontrol as fc\n",
    "import lab.fullcontrol as fclab"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### create a ***design***"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "EW, EH = 0.6, 0.2 # extrusion width and height\n",
    "radius, layers = 20, 40\n",
    "design_name = 'test_design'\n",
    "steps = fc.helixZ(fc.Point(x=50, y=50, z=EH), radius, radius, 0, layers, EH, layers*32)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### transform the design to a 'plot' ***result*** to preview it"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fc.transform(steps, 'plot', fc.PlotControls(style='tube', zoom=0.7, initialization_data={'extrusion_width': EW, 'extrusion_height': EH}))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### CodeControls()\n",
    "\n",
    " CodeControls adjust how a ***design*** is transformed into a 'control_code' ***result*** and has these attributes:\n",
    "- `code_format` - only '3mf' is currently supported\n",
    "- `controls` - for Bambulab printers, the .3mf file contains a gcode file, along with various other data and images. therefore it is necessary to supply GcodeControls as part of the data supplied in CodeControls to govern transformation to the 'control_code' (.3mf file) \n",
    "- `filename`- name of the .3mf file generated\n",
    "\n",
    "in this initial implementation, the  GcodeControls instance supplied as CodeControls.controls:\n",
    "- must have the 'printer_name' attribute setas 'bambulab_x1'\n",
    "- must not have the 'save_as' attribute set since the gcode is not saved... it is included in the 3mf file which is saved according to CodeControls.filename"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### transform the design to a .3mf file\n",
    "\n",
    "the 3mf is automatically saved in the working directory\n",
    "\n",
    "if using google colab, a download prompt will show in the browser"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "gcode_controls = fc.GcodeControls(\n",
    "    printer_name='bambulab_x1',\n",
    "    initialization_data={'extrusion_width': EW,'extrusion_height': EH})\n",
    "\n",
    "code_controls = fclab.CodeControls(code_format='3mf', controls=gcode_controls, filename=design_name)\n",
    "fclab.transform(steps, 'control_code', code_controls)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fc",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
